/**
 * 
 */
package at.ac.tuwien.swa075.telco.bc.service;

import java.sql.Timestamp;

import at.ac.tuwien.swa075.telco.bc.BCException;
import at.ac.tuwien.swa075.telco.bc.service.sdo.AccountSDO;

/**
 * 
 * @author Johannes Mayr <johannes.mayr@uniqa.at>
 */
public class BillingCenter implements IAccountService, IBookingService, IInvoiceService, ITransferService {
	
	/**
	 * Creates a new billing center
	 *
	 */
	public BillingCenter() {
	}

	/**
	 * Creates a new account in the billing system. An account is associated with a single device owned by a subscriber.
	 * @param account The account data.
	 * @return The account number of the newly created account.
	 * @throws BCException An error occurred while creating the account.
	 */
	public String createAccount(AccountSDO account) throws BCException {
		// Check if account doesn't exist already
		// Create new account using appropriate DAO
		// return account number
		return null;
	}

	/**
	 * Deletes an existing account if the aren't any unpayed bookings for that account.
	 * @param accountNumber The number of the account to delete.
	 * @throws BCException An error occurred.
	 */
	public void deleteAccount(String accountNumber) throws BCException {
		// Retrieve account to check
		// check if there are unpayed bookings for this account.
		// mark the account as deleted
		// store changes
	}

	/**
	 * Returns the accoutn for a given equipment id (imei)
	 * @param imei The imei that identifies the equipment.
	 * @return An account for the given device.
	 * @throws BCException An error occured during the search operation
	 */
	public AccountSDO findAccount(String imei) throws BCException {
		// use the account dao to retrieve the data
		// return an appropriate account object.
		return null;
	}

	/**
	 * Changes an existing account.
	 * 
	 * @param account The account data
	 * @exception An error occured while changing the data.
	 */
	public void updateAccount(AccountSDO account) throws BCException {
		// retrive the object from the database
		// update changed data (incl. consistency checks)
	}

	/**
	 * Books a single sms on an existing device.
	 * @param imei The device identity
	 * @throws BCException an error occured during the booking.
	 */
	public void bookMessage(String imei) throws BCException {
		// retrieve the account DAO and the accoring tarif DAO
		// calculate the amount for the booking
		// create a booking line with status assigned
		// and store it in the database
	}
	
	/**
	 * Transfers a certain amount of money to an account.
	 * @param accountNumber The account number
	 * @param amount The amount of money.
	 * @throws BCException An error occured during the transer.
	 */
	public void processMoneyTransfer(String accountNumber, double amount) {
		// retrive account data
		// mark as many bookings as paid as possible
		// move remaining money to the account as a plus if available
		// change account data
	}

	/**
	 * Calculates the total amount for a given period of time and debits the according account for all subscriber ids.
	 *  
	 * @param from Start of the time peroid
	 * @param to End of the time period
	 * @throws BCException An error 
	 */
	public void processInvoices(Timestamp from, Timestamp to) throws BCException {
		// retrieve a list of all accounts ordered by sbscribers
		// for everey account retrive all unbilled bookings within the given peroid
		// calculate the total amount and debit it to the account
		// mark all calculated bookings as billed
	}
	 
}
